package com.shuorikeji.huohuo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView;

import com.danikula.videocache.HttpProxyCacheServer;
import com.shuorikeji.huohuo.app.MyApplication;

import cn.jzvd.JzvdStd;

public class CustomJzvdStd extends JzvdStd {
    private Context context;
    public SeekBar sbJd;

    public CustomJzvdStd(Context context) {
        super(context);
        this.context = context;
    }

    public CustomJzvdStd(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    public void init(Context context) {
        super.init(context);
        findViewById(cn.jzvd.R.id.fullscreen).setVisibility(View.GONE);
        TextView tvTotalTime = findViewById(cn.jzvd.R.id.total);
        sbJd = findViewById(cn.jzvd.R.id.bottom_seek_progress);
        // 获取当前布局参数
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) tvTotalTime.getLayoutParams();
        params.setMargins(0, 0, 40, 0); // 左、上、右、下
        tvTotalTime.setLayoutParams(params);
    }

    @Override
    public void setUp(String url, String title, int screen, Class mClass) {
        super.setUp(url, title, screen, mClass);
        if (url.startsWith("http")) {
            HttpProxyCacheServer proxy = MyApplication.getProxy(context);
            String proxyUrl = proxy.getProxyUrl(url);
            super.setUp(proxyUrl, title, screen, mClass);
        } else {
            super.setUp(url, title, screen, mClass);
        }

    }

    @Override
    public void onStateAutoComplete() {
        super.onStateAutoComplete();
        Log.i("饺子播放器", "视频播放完成");
        startVideo();
    }

    public SeekBar getSnJd() {
        return sbJd;
    }
}
